package vn.edu.saigontech.ncms.model.result;

import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
import javax.persistence.Transient;

@Entity
@DiscriminatorValue("midterm_test")
@SuppressWarnings("serial")
public class MidtermTest extends AbstractTest {
	public static final double WEIGHT = 0.3;
	
	/**
	 * get the grade detail from the offering class
	 * 
	 * @return
	 */
	private GradeDetail getGradeDetail() {
		return this.getOfferingMember().getReceipt().getOffering().getMidtermGradeDetail();
	}

	public Double getTotal() {
		try {
			GradeDetail gradeDetail = this.getGradeDetail();
			double totalWritten = gradeDetail.computeTotalWritternScore(this);
			if ((totalWritten % 0.5) == 0)
				return totalWritten;
			return (double) Math.round(totalWritten);
		} catch (Exception ex) {
		}
		return null;
	}

	@Transient
	public Double getConvertedScore() {
		Double total = this.getTotal();
		if (total == null)
			return null;
		return total * WEIGHT;
	}
}